package com.yuejian_06.yuejian_06.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.activity.CoachVideoActivity;
import com.yuejian_06.yuejian_06.bean.CoachVideoBean;
import com.yuejian_06.yuejian_06.fragment.Constants;
import com.yuejian_06.yuejian_06.fragment.Constants_l;

import java.util.List;

/**
 * Created by songedwin on 2017/10/17.
 */

public class CoachVideoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public CoachVideoAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.coach_video_cardview, parent, false);
        return new CoachVideoAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final CoachVideoBean entity = (CoachVideoBean) mDataList.get(position);
        if (null == entity)
            return;
        CoachVideoAdapter.ViewHolder viewHolder = (CoachVideoAdapter.ViewHolder) holder;
        viewHolder.cv_name.setText(entity.getCv_name().toString());
        viewHolder.cv_star.setText(entity.getStar().toString());

        String internetUrl = Constants.SSS+"yuejian/Public/coachVideo/"+entity.getPic();
        if(!entity.getPic().isEmpty())
        {
            Picasso
                    .with(mContext)
                    .load(internetUrl)
                    .into(viewHolder.cv_pic);}
        else
        {
            viewHolder.cv_pic.setImageResource(R.drawable.club_wu);
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, CoachVideoActivity.class);
                intent.putExtra("cv_id",entity.getCoach_id());
                intent.putExtra("cv_name",entity.getCv_name());
                intent.putExtra("cv_video",entity.getCv_video());
                intent.putExtra("cv_intro",entity.getIntro());
                intent.putExtra("cv_star",entity.getStar());
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
       TextView cv_name,cv_star;
        ImageView cv_pic;
        public ViewHolder(View itemView) {
            super(itemView);
            cv_name=(TextView) itemView.findViewById(R.id.coach_video_name);
            cv_star=(TextView) itemView.findViewById(R.id.coach_video_star);
            cv_pic=(ImageView) itemView.findViewById(R.id.coach_video_pic);
        }
    }
}
